//
// Created by eruake on 2017/8/9.
//

#include <vector>
#include <iostream>

using namespace std;

int main() {
    vector<int> c;
    c.push_back(221111);
    c.push_back(22);
    c.push_back(232);
    c.push_back(22);
    c.push_back(232);
    c.push_back(22);
    c.push_back(232);
    // 对比capacity 与 size 的区别
    cout << c.capacity() <<endl;
    cout << c.max_size() << endl;
    cout << c.size() << endl;
    int a = c.front();
    cout << c.front() << endl;
    cout << c[0] << endl;

    cout  << "查找删除之前" << endl;
    if (!c.empty()) {
        cout << "c is not empty" << endl;
    }

    // 查找删除
    std::vector<int>::iterator pos;
    pos = find(c.begin(), c.end(), 232);
    if (pos != c.end()){
        c.erase(pos);
        cout << "删除数据" << endl;
    }

    pos = find(c.begin(), c.end(), 232);
    if (pos != c.end()){
        c.erase(pos);
        cout << "删除数据" << endl;
    }
    cout << c.size() << endl;
    cout << "使用find查找得到pos一次只能删除一个元素, 如何高效的删除内部相同的元素?" << endl;

    cout << "如何高效的把 vector 内部的数据打印出来" << " 使用 copy 到输出流 " <<endl;

    copy(c.begin(), c.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
    //如何交换vector内部的两个元素
    swap(c[0], c[2]);
    copy(c.begin(), c.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    // 在个某个位置插入数据
    c.insert(find(c.begin(), c.end(), 22), 3456788);
    cout << "在查找到 22 的第一个元素区插入数据,是之前还是之后, 当然是之前" << endl;
    copy(c.begin(), c.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    //改变最后一个元素
    cout << "最后一个元素重新赋值" << endl;
    c.back() = 1;
    copy(c.begin(), c.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    //改变最后一个元素
    cout << "第一个元素重新赋值" << endl;
    c.front() = 1;
    copy(c.begin(), c.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

}

